package com.ungs.reportes.datasource;

import java.util.ArrayList;
import java.util.List;

import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRField;

import com.ungs.entities.Incidente;
import com.ungs.utils.Fechas;

public class SolicitudCompraIncDS implements JRDataSource {
	private List<Incidente> incidenteList = new ArrayList<Incidente>();
	private int indice = -1;

	public boolean next() throws JRException {
		return ++indice < incidenteList.size();
	}

	public Object getFieldValue(JRField jrf) throws JRException {
		Object valor = null;

		if ("fechaIncidente".equals(jrf.getName())) {
			if (incidenteList.get(indice).getFechaIncidente() != null) {
				valor = Fechas.getFechaStringConHora(incidenteList.get(indice)
						.getFechaIncidente());
			} else {
				valor = "";
			}

		}

		if ("fechaCierre".equals(jrf.getName())) {
			if (incidenteList.get(indice).getFechaCierreIncidente() != null) {
				valor = Fechas.getFechaStringConHora(incidenteList.get(indice)
						.getFechaCierreIncidente());
			} else {
				valor = "";
			}

		}

		if ("observaciones".equals(jrf.getName())) {
			if (incidenteList.get(indice).getObservaciones() != null) {
				valor = incidenteList.get(indice).getObservaciones();
			} else {
				valor = "";
			}

		}

		return valor;
	}

	public void addIncidente(Incidente incidente) {
		this.incidenteList.add(incidente);
	}

	public void addIncidenteList(List<Incidente> incidenteList) {
		this.incidenteList = incidenteList;
	}

}
